package org.dxy.trigger.http;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dxy.api.dto.response.R;
import org.dxy.api.dto.request.holiday.GetHolidayDataRequest;
import org.dxy.api.dto.request.holiday.SaveHolidayDataRequest;
import org.dxy.api.dto.request.holiday.BatchSaveHolidayDataRequest;
import org.dxy.trigger.http.service.HolidayApplicationService;
import org.springframework.web.bind.annotation.*;


/**
 * 假期管理控制器
 * 
 * @author dxy
 * @createTime 2025/9/21
 */
@Slf4j
@RestController
@RequestMapping("/api/holiday")
@RequiredArgsConstructor
public class HolidayController {

    private final HolidayApplicationService holidayApplicationService;

    /**
     * 获取指定月份的假期数据
     */
    @GetMapping("/data")
    public R getHolidayData(@Valid GetHolidayDataRequest request) {
        log.info("获取假期数据，参数：{}", request);
        return R.ok(holidayApplicationService.getHolidayData(request));
    }

    /**
     * 保存单个假期数据
     */
    @PostMapping("/save")
    public R saveHolidayData(@Valid @RequestBody SaveHolidayDataRequest request) {
        log.info("保存假期数据，参数：{}", request);
        holidayApplicationService.saveHolidayData(request);
        return R.ok("保存成功");
    }

    /**
     * 批量保存假期数据
     */
    @PostMapping("/batch-save")
    public R batchSaveHolidayData(@Valid @RequestBody BatchSaveHolidayDataRequest request) {
        log.info("批量保存假期数据，参数：{}", request);
        holidayApplicationService.batchSaveHolidayData(request);
        return R.ok("批量保存成功");
    }

    /**
     * 删除假期数据
     */
    @DeleteMapping("/delete/{date}")
    public R deleteHolidayData(@PathVariable String date) {
        log.info("删除假期数据，日期：{}", date);
        holidayApplicationService.deleteHolidayData(date);
        return R.ok("删除成功");
    }

    /**
     * 获取假期统计数据
     */
    @GetMapping("/statistics")
    public R getHolidayStatistics(@RequestParam Integer year) {
        log.info("获取假期统计数据，年份：{}", year);
        return R.ok(holidayApplicationService.getHolidayStatistics(year));
    }
}